package com.dj.mingkong.common.util;

public class HexUtils {
    public HexUtils() {
    }

    public static String byteToHex(byte[] bytes) {
        StringBuilder sb = new StringBuilder();
        byte[] var2 = bytes;
        int var3 = bytes.length;

        for (int var4 = 0; var4 < var3; ++var4) {
            byte aByte = var2[var4];
            String hex = Integer.toHexString(aByte & 255);
            if (hex.length() < 2) {
                sb.append(0);
            }

            sb.append(hex);
        }

        return sb.toString();
    }

    public static byte[] hexToBytes(String hex) {
        String tmp = hex.length() % 2 != 0 ? "0" + hex : hex;
        byte[] b = new byte[tmp.length() / 2];

        for (int i = 0; i < b.length; ++i) {
            int index = i * 2;
            int v = Integer.parseInt(hex.substring(index, index + 2), 16);
            b[i] = (byte) v;
        }

        return b;
    }
}
